Replication Data for: Single shot imaging with randomized structured illumination at a free electron laser
---------------------

This dataset contains the data and scripts required to generate the figures and analysis included in the experimental portion of the preprint, "Single shot imaging with randomized structured illumination at a free electron laser". The exact figures in the paper can be regenerated by running the "view\_\*.py" scripts, which plot stored analysis results. The analysis can also be regenerated using the "reconstruct\_\*.py" scripts.

Below is a listing of the included files and their role. Running this code requires an installation of the [cdtools library](https://github.com/cdtools-developers/cdtools). The code contained here was most recently tested with the version of the code corresponding to commit [0020306dd510b35b8d132c3826a06495f462bca7](https://github.com/cdtools-developers/cdtools/tree/0020306dd510b35b8d132c3826a06495f462bca7).

Finally, note that because the cdtools library has been under active development and the included reconstruction algorithms have improved, rerunning the ptychography and RPI reconstructions produce slightly different results than those included in the paper figures. The differences are minor and amount to very small but repeatable improvements in the spectral signal-to-noise ratio of ptychography and RPI results. The centering of the arc used to plot the linecut may also need to be updated after rerunning the reconstructions, because the centering of the reconstructed probe is not fully repeatable

File Descriptions
=================

### view\_ptycho.py

This file plots the results of the ptychography reconstructions, as well as the various associated quality metrics. This uses the saved reconstruction results included in the results folder, and will produce identical results to the figures included in the paper, excluding minor formatting changes.

WARNING: After running "reconstruct\_ptycho\_polished.py", which regenerates the ptychography reconstructions, "view\_ptycho.py" will produce output that is no longer identical to the results in the paper. The original reconstruction outputs can always be re-downloaded.

### view\_rpi.py

This file plots the results of the randomized probe imaging reconstructions, as well as the various associated quality metrics. This uses the saved reconstruction results included in the results folder, and will produce identical results to the figures included in the paper, excluding minor formatting changes.

WARNING: After running "reconstruct\_rpi.py", which regenerates the RPI reconstructions, "view\_rpi.py" will produce output that is no longer identical to the results in the paper. The original reconstruction outputs can always be re-downloaded.

### view\_magnetic\_ptycho\_lcp.py

This file plots the results of the ptychography reconstructions on the magnetic sample which used right hand circularly polarized light, as well as the various associated quality metrics. This uses the saved reconstruction results included in the results folder, and will produce identical results to the figures included in the paper, excluding minor formatting changes.

WARNING: After running "reconstruct\_magnetic\_ptycho\_lcp.py", which regenerates the RPI reconstructions, "view\_magnetic\_ptycho\_lcp.py" will produce output that is no longer identical to the results in the paper. The original reconstruction outputs can always be re-downloaded.

### view\_magnetic\_ptycho\_rcp.py

This file plots the results of the ptychography reconstructions on the magnetic sample which used right hand circularly polarized light, as well as the various associated quality metrics. This uses the saved reconstruction results included in the results folder, and will produce identical results to the figures included in the paper, excluding minor formatting changes.

WARNING: After running "reconstruct\_magnetic\_ptycho\_rcp.py", which regenerates the RPI reconstructions, "view\_magnetic\_ptycho\_rcp.py" will produce output that is no longer identical to the results in the paper. The original reconstruction outputs can always be re-downloaded.

### view\_magnetic\_rpi\_lcp.py

This file plots the results of the ptychography reconstructions on the magnetic sample which used right hand circularly polarized light, as well as the various associated quality metrics. This uses the saved reconstruction results included in the results folder, and will produce identical results to the figures included in the paper, excluding minor formatting changes.

WARNING: After running "reconstruct\_magnetic\_rpi\_lcp.py", which regenerates the RPI reconstructions, "view\_magnetic\_rpi\_lcp.py" will produce output that is no longer identical to the results in the paper. The original reconstruction outputs can always be re-downloaded.

### reconstruct\_ptycho\_rough.py

This will rerun the initial, rough ptychography reconstruction which is used to seed the probe for the final, high quality ptychography reconstruction of the Siemens star.

### reconstruct\_ptycho\_polished.py

This will rerun the final, high quality ptychography reconstruction of a Siemens start which is reported in the paper. Running this will overwrite the existing reconstruction results. After this is run, the "view\_ptycho.py" scripts will output similar, but no longer identical results, to the figures contained in the paper.

### reconstruct\_rpi.py

This will rerun the RPI reconstructions on the Siemens star which are reported in the paper. Running this will overwrite the existing reconstruction results. After this is run, the "view\_rpi.py" script will output similar, but no longer identical results, to the figures contained in the paper.

### reconstruct\_magnetic\_ptycho\_lcp.py

This will rerun the ptychography reconstruction of a magnetic sample using left hand circularly polarized light. Running this will overwrite the existing reconstruction results. After this is run, the "view\_magnetic\_ptycho\_lcp.py" scripts will output similar, but no longer identical results, to the figures contained in the paper.

### reconstruct\_magnetic\_ptycho\_rcp.py

This will rerun the ptychography reconstruction of a magnetic sample using right hand circularly polarized light. Running this will overwrite the existing reconstruction results. After this is run, the "view\_magnetic\_ptycho\_lcp.py" scripts will output similar, but no longer identical results, to the figures contained in the paper.

### reconstruct\_magnetic\_rpi\_lcp.py

This will rerun the RPI reconstructions on a magnetic sample using left hand circularly polarized light, which are reported in the paper. Running this will overwrite the existing reconstruction results. After this is run, the "view\_magnetic\_rpi\_lcp.py" script will output similar, but no longer identical results, to the figures contained in the paper.

### helper\_functions.py

This file contains several functions which are used to help reconstruct and analyze the results. In particular, the code which calculates the various spectral signal-to-noise ratios (SSNR), and performs alignment of various images, is contained here.

### prep\_data.py

This is a script which was run to map from the .cxi files generated at the beamline, which contain raw data from the experiment packed into a .cxi format, to the lightly edited .cxi files contained here, which have (for example) several bad frames of data removed.

### prep\_magnetic\_data.py

This does the same as "prep\_data.py", but for the various magnetic datasets

### random\_selection.npy

This is a precomputed random selection which was used to repeatably partition the ptychography dataset for Fourier ring correlation analysis. The code used to generate it is contained in "helper\_functions.py".
